import type { ColumnsType } from 'antd/es/table';
import React, { useState } from 'react';
import DragTreeTable from '@/components/DragTreeTable/index';

interface DataType {
  key: string;
  name: string;
  age: number;
  address: string;
}
const columns: ColumnsType<DataType> = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
];

const App: React.FC = () => {
  const [data, setData] = useState([
    {
      key: '1',
      name: 'John Brown',
      age: 32,
      address: 'New York No. 1 Lake Park',
    },
    {
      key: '2',
      name: 'Jim Green',
      age: 42,
      address: 'London No. 1 Lake Park',
    },
    {
      key: '2-1',
      name: 'Jim Green-1',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      pid: '2',
    },
    {
      key: '2-2',
      name: 'Jim Green-2',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      pid: '2',
    },
    {
      key: '3',
      name: 'Tom Black',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
    },
    {
      key: '3-1',
      name: 'Tom Black-1',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      pid: '3',
    },
    {
      key: '3-2',
      name: 'Tom Black-2',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      pid: '3',
    },
    {
      key: '3-3',
      name: 'Tom Black-3',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      pid: '3',
    },
    {
      key: '3-3-1',
      name: 'Tom Black-3-1',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      pid: '3-3',
    },
    {
      key: '3-3-2',
      name: 'Tom Black-3-2',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
      pid: '3-3',
    },
  ]);

  const draged = (updateData: Record<string, any>[]) => {
    console.table(updateData);
  };

  return (
    <DragTreeTable
      idKey="key"
      enableDragSomeLevel={true}
      columns={columns}
      dataSource={data}
      draged={draged}
    />
  );
};

export default App;
